package com.iknow.activity;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.text.Editable;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.iknow.IKnow;
import com.iknow.app.IKnowSystemConfig;
import com.iknow.db.IKnowDataBase;
import com.iknow.file.CacheSystem;
import com.iknow.image.ImageManager;
import com.iknow.image.ProfileImageCacheCallback;
import com.iknow.image.ProfileImageCacheManager;
import com.iknow.ui.model.XmppMessageAdapter;
import com.iknow.util.DomXmlUtil;
import com.iknow.util.Loger;
import com.iknow.util.StringUtil;
import com.iknow.xmpp.service.AudioMessage;
import com.iknow.xmpp.service.Contact;
import com.iknow.xmpp.service.Friend;
import com.iknow.xmpp.service.ImageMessage;
import com.iknow.xmpp.service.Message;
import com.iknow.xmpp.service.PresenceAdapter;
import com.iknow.xmpp.service.XmppBroadcastReceiver;
import com.iknow.xmpp.service.aidl.IBeemRosterListener.Stub;
import com.iknow.xmpp.service.aidl.IChat;
import com.iknow.xmpp.service.aidl.IChatManager;
import com.iknow.xmpp.service.aidl.IChatManagerListener;
import com.iknow.xmpp.service.aidl.IChatManagerListener.Stub;
import com.iknow.xmpp.service.aidl.IMessageListener;
import com.iknow.xmpp.service.aidl.IMessageListener.Stub;
import com.iknow.xmpp.service.aidl.IRoster;
import com.iknow.xmpp.service.aidl.IXmppFacade;
import com.iknow.xmpp.service.aidl.IXmppFacade.Stub;
import com.mobclick.android.MobclickAgent;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.util.StringUtils;
import org.w3c.dom.Node;

public class XmppChatActivity extends Activity
{
  private static final int REQUEST_IMAGE_CAPTURE = 2;
  private static final int REQUEST_PHOTO_LIBRARY = 3;
  private static final Intent SERVICE_INTENT = new Intent();
  private static final String TAG = "Chat";
  private View.OnClickListener ButtonSendAudipClickListener;
  private View.OnClickListener ButtonSendImageClickListener;
  private View.OnClickListener ButtonSendMsgClickListener;
  private View.OnClickListener UserHeadClickListener;
  private String mAcountId;
  private XmppMessageAdapter mAdapter;
  String mAudioFile;
  private boolean mBRecording;
  private boolean mBinded;
  private Button mButtonSendAudio;
  private Button mButtonSendImage;
  private Button mButtonSendmsg;
  private IChat mChat;
  private IChatManager mChatManager;
  private final IChatManagerListener mChatManagerListener;
  private final ComparatorMessageListByTime<Message> mComparator;
  private XmppServiceConnection mConn;
  private Contact mContact;
  private EditText mEditText_msg;
  private String mFriendID;
  private String mFriendName;
  private Handler mHandler = new Handler();
  public ImageView mHeadImg;
  private File mImageFile;
  private Uri mImageUri;
  private final List<Message> mListMessages = new ArrayList();
  private ListView mListView;
  private final IMessageListener mMessageListener;
  MediaRecorder mRcorder;
  private final XmppBroadcastReceiver mReceiver;
  private IRoster mRoster;
  private final IKnowRosterListener mRosterListener;
  private FrameLayout mStatusImg;
  private String mTempImageFileName;
  public TextView mUsername;
  private IXmppFacade mXmppFacade;

  static
  {
    SERVICE_INTENT.setComponent(new ComponentName("com.iknow", "com.iknow.xmpp.service.IKnowXmppService"));
  }

  public XmppChatActivity()
  {
    this.mComparator = new ComparatorMessageListByTime();
    this.mConn = new XmppServiceConnection(this, null);
    this.mMessageListener = new OnMessageListener(this, null);
    this.mChatManagerListener = new ChatManagerListener(this, null);
    this.mRosterListener = new IKnowRosterListener(this, null);
    this.mReceiver = new XmppBroadcastReceiver();
    this.mAdapter = null;
    this.mListView = null;
    this.mEditText_msg = null;
    this.mButtonSendmsg = null;
    this.mButtonSendAudio = null;
    this.mButtonSendImage = null;
    this.mHeadImg = null;
    this.mUsername = null;
    this.UserHeadClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        Friend localFriend = IKnow.mIKnowDataBase.getFriendInfo(XmppChatActivity.access$0(this.this$0));
        Intent localIntent = new Intent(this.this$0, FriendActivity.class);
        if (localFriend != null)
          localIntent.putExtra("friend", localFriend);
        while (true)
        {
          this.this$0.startActivity(localIntent);
          return;
          localIntent.putExtra("friendID", XmppChatActivity.access$0(this.this$0));
        }
      }
    };
    this.ButtonSendMsgClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (!(((IKnow)this.this$0.getApplication()).isConnected()))
          Toast.makeText(this.this$0, this.this$0.getString(2131361959), 0).show();
        while (true)
        {
          while (true)
          {
            return;
            if (!(StringUtil.isEmpty(XmppChatActivity.access$1(this.this$0).getText().toString())))
              break;
            Toast.makeText(this.this$0, this.this$0.getString(2131361961), 0).show();
          }
          XmppChatActivity.access$2(this.this$0, XmppChatActivity.access$1(this.this$0).getText().toString(), null);
        }
      }
    };
    this.mBRecording = false;
    this.mRcorder = new MediaRecorder();
    this.ButtonSendAudipClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        if (XmppChatActivity.access$3(this.this$0))
          XmppChatActivity.access$4(this.this$0, false);
      }
    };
    this.ButtonSendImageClickListener = new View.OnClickListener(this)
    {
      public void onClick()
      {
        CharSequence[] arrayOfCharSequence = new CharSequence[2];
        arrayOfCharSequence[0] = this.this$0.getString(2131361973);
        arrayOfCharSequence[1] = this.this$0.getString(2131361974);
        AlertDialog.Builder localBuilder = new AlertDialog.Builder(this.this$0);
        localBuilder.setTitle(this.this$0.getString(2131361975));
        localBuilder.setItems(arrayOfCharSequence, new DialogInterface.OnClickListener(this)
        {
          public void onClick(, int paramInt)
          {
            switch (paramInt)
            {
            default:
            case 0:
            case 1:
            }
            while (true)
            {
              while (true)
              {
                return;
                XmppChatActivity.access$5(XmppChatActivity.4.access$0(this.this$1));
              }
              XmppChatActivity.access$6(XmppChatActivity.4.access$0(this.this$1));
            }
          }
        });
        localBuilder.create().show();
      }
    };
    this.mTempImageFileName = null;
  }

  private void changeCurrentChat(Contact paramContact)
    throws RemoteException
  {
    if (this.mChat != null)
    {
      this.mChat.setOpen(false);
      this.mChat.removeMessageListener(this.mMessageListener);
    }
    this.mChat = this.mChatManager.getChat(paramContact);
    if (this.mChat != null)
    {
      this.mChat.setOpen(true);
      this.mChat.addMessageListener(this.mMessageListener);
      this.mChatManager.deleteChatNotification(this.mChat);
    }
    this.mContact = this.mRoster.getContact(paramContact.getJID());
    String str = paramContact.getSelectedRes();
    if (this.mContact == null)
      this.mContact = paramContact;
    if (!("".equals(str)))
      this.mContact.setSelectedRes(str);
    updatePresenceIcon();
  }

  private void getMessageFromLocalDB()
  {
    this.mListMessages.clear();
    Iterator localIterator = IKnow.mIKnowDataBase.getXmppMessage(this.mAcountId, this.mFriendID).iterator();
    while (true)
    {
      if (!(localIterator.hasNext()))
      {
        this.mAdapter.notifyDataSetChanged();
        sortMsgList();
        return;
      }
      paseMessage((Message)localIterator.next());
    }
  }

  private void initView()
  {
    this.mHeadImg = ((ImageView)findViewById(2131296307));
    this.mStatusImg = ((FrameLayout)findViewById(2131296306));
    this.mStatusImg.setOnClickListener(this.UserHeadClickListener);
    this.mUsername = ((TextView)findViewById(2131296308));
    this.mListView = ((ListView)findViewById(2131296305));
    this.mListView.setDivider(null);
    this.mListView.setAdapter(this.mAdapter);
    this.mEditText_msg = ((EditText)findViewById(2131296428));
    this.mButtonSendmsg = ((Button)findViewById(2131296429));
    this.mButtonSendmsg.setOnClickListener(this.ButtonSendMsgClickListener);
    this.mButtonSendAudio = ((Button)findViewById(2131296431));
    this.mButtonSendAudio.setOnClickListener(this.ButtonSendAudipClickListener);
    this.mButtonSendImage = ((Button)findViewById(2131296430));
    this.mButtonSendImage.setOnClickListener(this.ButtonSendImageClickListener);
  }

  private void onImageSelected(String paramString)
  {
    ImageManager localImageManager = IKnow.mProfileImageCacheManager.getImageManager();
    String str = IKnow.mCacheSystem.getThumbmailFileName(paramString);
    if (localImageManager.bitmapToFile(localImageManager.createThumbnailBitmap(Uri.parse("file://" + paramString), 600), str) != null)
      sendImageMessage(paramString, str);
  }

  private void onImageSelected(String paramString, Uri paramUri)
  {
    ImageManager localImageManager = IKnow.mProfileImageCacheManager.getImageManager();
    String str = IKnow.mCacheSystem.getThumbmailFileName(paramString);
    if (localImageManager.bitmapToFile(localImageManager.createThumbnailBitmap(paramUri, 600), str) != null)
      sendImageMessage(paramString, str);
  }

  private void openImageCaptureMenu()
  {
    try
    {
      this.mImageFile = new File(IKnow.mCacheSystem.createImagefileName());
      this.mImageUri = Uri.fromFile(this.mImageFile);
      Intent localIntent = new Intent("android.media.action.IMAGE_CAPTURE");
      localIntent.putExtra("output", this.mImageUri);
      startActivityForResult(localIntent, 2);
      return;
    }
    catch (Exception localException)
    {
      Loger.e("Chat", localException.getMessage());
    }
  }

  private void openPhotoLibraryMenu()
  {
    Intent localIntent = new Intent("android.intent.action.GET_CONTENT");
    localIntent.setType("image/*");
    localIntent.putExtra("crop", "true");
    localIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
    File localFile = IKnow.mCacheSystem.createImageFile();
    this.mTempImageFileName = localFile.getAbsolutePath();
    localIntent.putExtra("output", Uri.fromFile(localFile));
    startActivityForResult(localIntent, 3);
  }

  private void paseMessage(Message paramMessage)
  {
    String str = paramMessage.getBody();
    if (str.indexOf("<audio") != -1)
    {
      AudioMessage localAudioMessage = new AudioMessage(paramMessage.getTo(), paramMessage.getType());
      Node localNode1 = DomXmlUtil.paseXml(paramMessage.getBody());
      localAudioMessage.setFrom(StringUtils.parseBareAddress(paramMessage.getFrom()));
      localAudioMessage.setBody(paramMessage.getBody());
      localAudioMessage.setMessageStatus(paramMessage.getStatus());
      localAudioMessage.setTimestamp(paramMessage.getTimestamp());
      localAudioMessage.setFileName(DomXmlUtil.getAttributes(localNode1, "src"));
      this.mListMessages.add(localAudioMessage);
    }
    if (str.indexOf("<image") != -1)
    {
      ImageMessage localImageMessage = new ImageMessage(paramMessage.getTo(), paramMessage.getType());
      Node localNode2 = DomXmlUtil.paseXml(paramMessage.getBody());
      localImageMessage.setFrom(StringUtils.parseBareAddress(paramMessage.getFrom()));
      localImageMessage.setBody(paramMessage.getBody());
      localImageMessage.setStatus(paramMessage.getStatus());
      localImageMessage.setSubject(paramMessage.getSubject());
      localImageMessage.setTimestamp(paramMessage.getTimestamp());
      localImageMessage.setFileName(DomXmlUtil.getAttributes(localNode2, "src"));
      this.mListMessages.add(localImageMessage);
    }
    while (true)
    {
      return;
      this.mListMessages.add(paramMessage);
    }
  }

  private void sendAudioMessage(String paramString)
  {
    Object[] arrayOfObject = new Object[1];
    arrayOfObject[0] = paramString;
    String str = String.format("<audio src='%s'/>", arrayOfObject);
    AudioMessage localAudioMessage = new AudioMessage(this.mContact.getJIDWithRes(), 200);
    localAudioMessage.setBody(str);
    localAudioMessage.setFileName(paramString);
    try
    {
      if (this.mChat == null)
      {
        this.mChat = this.mChatManager.createChat(this.mContact, this.mMessageListener);
        this.mChat.setOpen(true);
      }
      localAudioMessage.setiKnowMsgType(18);
      localAudioMessage.setFrom(this.mAcountId);
      this.mListMessages.add(localAudioMessage);
      this.mAdapter.notifyDataSetChanged();
      this.mChat.sendMessage(localAudioMessage);
      return;
    }
    catch (RemoteException localRemoteException)
    {
      Loger.e("Chat", localRemoteException.getMessage());
    }
  }

  private void sendImageMessage(String paramString1, String paramString2)
  {
    paramString1.substring(1 + paramString1.lastIndexOf(File.separator), paramString1.length());
    ImageMessage localImageMessage = new ImageMessage(this.mContact.getJIDWithRes(), 200);
    localImageMessage.setFileName(paramString1);
    localImageMessage.setThumbnail(paramString2);
    try
    {
      if (this.mChat == null)
      {
        this.mChat = this.mChatManager.createChat(this.mContact, this.mMessageListener);
        this.mChat.setOpen(true);
      }
      localImageMessage.setiKnowMsgType(17);
      localImageMessage.setFrom(StringUtils.parseBareAddress(this.mAcountId));
      this.mListMessages.add(localImageMessage);
      this.mChat.sendMessage(localImageMessage);
      this.mAdapter.notifyDataSetChanged();
      return;
    }
    catch (RemoteException localRemoteException)
    {
      Loger.e("Chat", localRemoteException.getMessage());
    }
  }

  private void sendMessage(String paramString1, String paramString2)
  {
    if ((this.mXmppFacade == null) || (this.mChatManager == null))
    {
      Loger.e("Chat", "connection error!!");
      Toast.makeText(this, getString(2131361959), 0).show();
      return;
    }
    MobclickAgent.onEvent(this, "send_message");
    Message localMessage = new Message(this.mContact.getJIDWithRes(), 200);
    localMessage.setBody(paramString1);
    localMessage.setSubject(paramString2);
    try
    {
      if (this.mChat == null)
      {
        this.mChat = this.mChatManager.createChat(this.mContact, this.mMessageListener);
        this.mChat.setOpen(true);
      }
      localMessage.setiKnowMsgType(16);
      localMessage.setFrom(StringUtils.parseBareAddress(this.mAcountId));
      this.mListMessages.add(localMessage);
      this.mChat.sendMessage(localMessage);
      this.mAdapter.notifyDataSetChanged();
      this.mEditText_msg.setText(null);
    }
    catch (RemoteException localRemoteException)
    {
      Loger.e("Chat", localRemoteException.getMessage());
    }
    catch (NullPointerException localNullPointerException)
    {
      Loger.e("Chat", "connection error!!");
      Toast.makeText(this, getString(2131361959), 0).show();
    }
  }

  private void sortMsgList()
  {
    Collections.sort(this.mListMessages, this.mComparator);
  }

  private void updatePresenceIcon()
  {
    if (this.mContact.getStatus() == 500)
      this.mStatusImg.setBackgroundResource(2130837758);
    while (true)
    {
      return;
      this.mStatusImg.setBackgroundResource(2130837761);
    }
  }

  protected void onActivityResult(int paramInt1, int paramInt2, Intent paramIntent)
  {
    if ((paramInt1 == 2) && (paramInt2 == -1))
      onImageSelected(this.mImageFile.getAbsolutePath());
    while (true)
    {
      do
        return;
      while ((paramInt1 != 3) || (paramInt2 != -1));
      onImageSelected(this.mTempImageFileName, Uri.parse(paramIntent.getAction()));
    }
  }

  protected void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    requestWindowFeature(1);
    setContentView(2130903052);
    registerReceiver(this.mReceiver, new IntentFilter("IKnowConnectionClosed"));
    this.mAcountId = IKnow.mSystemConfig.getString("account_username");
    this.mAdapter = new XmppMessageAdapter(this, getLayoutInflater());
    this.mAdapter.setMessageList(this.mListMessages);
    this.mAdapter.setUserJid(this.mAcountId);
    initView();
  }

  protected void onDestroy()
  {
    unregisterReceiver(this.mReceiver);
    super.onDestroy();
  }

  protected void onNewIntent(Intent paramIntent)
  {
    super.onNewIntent(paramIntent);
    setIntent(paramIntent);
  }

  protected void onPause()
  {
    super.onPause();
    try
    {
      if (this.mChat != null)
      {
        this.mChat.setOpen(false);
        this.mChat.removeMessageListener(this.mMessageListener);
      }
      if (this.mRoster != null)
        this.mRoster.removeRosterListener(this.mRosterListener);
      if (this.mChatManager != null)
        this.mChatManager.removeChatCreationListener(this.mChatManagerListener);
      if (this.mBinded)
      {
        unbindService(this.mConn);
        this.mBinded = false;
      }
      IKnow.mIKnowDataBase.setSessionReaded(this.mFriendID);
      this.mXmppFacade = null;
      this.mRoster = null;
      this.mChat = null;
      this.mContact = null;
      this.mChatManager = null;
      MobclickAgent.onPause(this);
      return;
    }
    catch (RemoteException localRemoteException)
    {
      Loger.e("Chat", localRemoteException.getMessage());
    }
  }

  protected void onRestoreInstanceState(Bundle paramBundle)
  {
    super.onRestoreInstanceState(paramBundle);
  }

  protected void onResume()
  {
    this.mFriendName = getIntent().getStringExtra("name");
    this.mFriendID = getIntent().getStringExtra("friend_jid");
    this.mContact = ((Contact)getIntent().getParcelableExtra("contact"));
    IKnow.mIKnowDataBase.setSessionReaded(this.mFriendID);
    IKnow localIKnow = (IKnow)getApplication();
    if ((localIKnow.isConnected()) && (!(this.mBinded)) && (localIKnow.isAccountConfigured()))
      this.mBinded = bindService(SERVICE_INTENT, this.mConn, 1);
    this.mUsername.setText(this.mFriendName);
    String str = IKnow.mIKnowDataBase.getFriendAvatarUrl(this.mFriendID);
    if (!(StringUtil.isEmpty(str)))
      this.mHeadImg.setImageBitmap(IKnow.mProfileImageCacheManager.getProfileImage(str, new CallBack(this, null)));
    getMessageFromLocalDB();
    MobclickAgent.onResume(this);
    MobclickAgent.setSessionContinueMillis(600000L);
    super.onResume();
  }

  protected void onSaveInstanceState(Bundle paramBundle)
  {
    super.onSaveInstanceState(paramBundle);
  }

  private class CallBack
  implements ProfileImageCacheCallback
  {
    public void refresh(, Bitmap paramBitmap)
    {
      this.this$0.mHeadImg.setImageBitmap(paramBitmap);
    }
  }

  private class ChatManagerListener extends IChatManagerListener.Stub
  {
    public void chatCreated(, boolean paramBoolean)
      throws RemoteException
    {
      if (paramBoolean)
        return;
      try
      {
        String str;
        do
          str = XmppChatActivity.access$15(this.this$0).getJID();
        while (!(paramIChat.getParticipant().getJID().equals(str)));
        if (XmppChatActivity.access$17(this.this$0) != null)
        {
          XmppChatActivity.access$17(this.this$0).setOpen(false);
          XmppChatActivity.access$17(this.this$0).removeMessageListener(XmppChatActivity.access$18(this.this$0));
        }
        XmppChatActivity.access$19(this.this$0, paramIChat);
        XmppChatActivity.access$17(this.this$0).setOpen(true);
        XmppChatActivity.access$17(this.this$0).addMessageListener(XmppChatActivity.access$18(this.this$0));
        XmppChatActivity.access$13(this.this$0).deleteChatNotification(XmppChatActivity.access$17(this.this$0));
      }
      catch (RemoteException localRemoteException)
      {
        Loger.e("Chat", "A remote exception occurs during the creation of a chat", localRemoteException);
      }
    }
  }

  public static final class ComparatorMessageListByTime<T>
  implements Comparator<T>
  {
    public int compare(T paramT1, T paramT2)
    {
      int i;
      if (((Message)paramT1).getTimestamp().before(((Message)paramT2).getTimestamp()))
        i = -1;
      while (true)
      {
        while (true)
        {
          return i;
          if (!(((Message)paramT1).getTimestamp().after(((Message)paramT2).getTimestamp())))
            break;
          i = 1;
        }
        i = 0;
      }
    }
  }

  private class IKnowRosterListener extends IBeemRosterListener.Stub
  {
    public void onEntriesAdded()
      throws RemoteException
    {
    }

    public void onEntriesDeleted()
      throws RemoteException
    {
    }

    public void onEntriesUpdated()
      throws RemoteException
    {
    }

    public void onPresenceChanged()
      throws RemoteException
    {
      if (XmppChatActivity.access$15(this.this$0).getJID().equals(StringUtils.parseBareAddress(paramPresenceAdapter.getFrom())))
        XmppChatActivity.access$20(this.this$0).post(new Runnable(this, paramPresenceAdapter)
        {
          public void run()
          {
            XmppChatActivity.access$15(XmppChatActivity.IKnowRosterListener.access$1(this.this$1)).setStatus(this.val$presence.getStatus());
            XmppChatActivity.access$15(XmppChatActivity.IKnowRosterListener.access$1(this.this$1)).setMsgState(this.val$presence.getStatusText());
            XmppChatActivity.access$23(XmppChatActivity.IKnowRosterListener.access$1(this.this$1));
          }
        });
    }
  }

  private class OnMessageListener extends IMessageListener.Stub
  {
    public void processMessage(, Message paramMessage)
      throws RemoteException
    {
      String str = StringUtils.parseBareAddress(paramMessage.getFrom());
      if (XmppChatActivity.access$15(this.this$0).getJID().equals(str))
        XmppChatActivity.access$20(this.this$0).post(new Runnable(this, paramMessage)
        {
          public void run()
          {
            if (this.val$msg.getType() == 400)
            {
              XmppChatActivity.access$21(XmppChatActivity.OnMessageListener.access$1(this.this$1)).add(this.val$msg);
              XmppChatActivity.access$22(XmppChatActivity.OnMessageListener.access$1(this.this$1)).notifyDataSetChanged();
            }
            while (true)
            {
              do
                return;
              while (this.val$msg.getBody() == null);
              if (this.val$msg.getBody() != null)
                XmppChatActivity.access$21(XmppChatActivity.OnMessageListener.access$1(this.this$1)).add(this.val$msg);
              XmppChatActivity.access$22(XmppChatActivity.OnMessageListener.access$1(this.this$1)).notifyDataSetChanged();
            }
          }
        });
    }

    public void stateChanged()
      throws RemoteException
    {
      String str = paramIChat.getState();
      XmppChatActivity.access$20(this.this$0).post(new Runnable(this, str)
      {
        public void run()
        {
          if ("active".equals(this.val$state))
            XmppChatActivity.OnMessageListener.access$1(this.this$1).getString(2131361971);
          while (true)
          {
            do
              while (true)
              {
                while (true)
                {
                  while (true)
                  {
                    return;
                    if (!("composing".equals(this.val$state)))
                      break;
                    XmppChatActivity.OnMessageListener.access$1(this.this$1).getString(2131361969);
                  }
                  if (!("gone".equals(this.val$state)))
                    break;
                  XmppChatActivity.OnMessageListener.access$1(this.this$1).getString(2131361970);
                }
                if (!("inactive".equals(this.val$state)))
                  break;
                XmppChatActivity.OnMessageListener.access$1(this.this$1).getString(2131361972);
              }
            while (!("paused".equals(this.val$state)));
            XmppChatActivity.OnMessageListener.access$1(this.this$1).getString(2131361971);
          }
        }
      });
    }
  }

  private class XmppServiceConnection
  implements ServiceConnection
  {
    public void onServiceConnected(, IBinder paramIBinder)
    {
      XmppChatActivity.access$7(this.this$0, IXmppFacade.Stub.asInterface(paramIBinder));
      try
      {
        XmppChatActivity.access$9(this.this$0, XmppChatActivity.access$8(this.this$0).getRoster());
        if (XmppChatActivity.access$10(this.this$0) == null)
          return;
        if (XmppChatActivity.access$10(this.this$0) != null)
          XmppChatActivity.access$10(this.this$0).addRosterListener(XmppChatActivity.access$11(this.this$0));
        XmppChatActivity.access$12(this.this$0, XmppChatActivity.access$8(this.this$0).getChatManager());
        if (XmppChatActivity.access$13(this.this$0) != null)
        {
          XmppChatActivity.access$13(this.this$0).addChatCreationListener(XmppChatActivity.access$14(this.this$0));
          XmppChatActivity.access$16(this.this$0, XmppChatActivity.access$15(this.this$0));
        }
      }
      catch (RemoteException localRemoteException)
      {
        Loger.e("Chat", localRemoteException.getMessage());
      }
    }

    public void onServiceDisconnected()
    {
      XmppChatActivity.access$7(this.this$0, null);
      try
      {
        if (XmppChatActivity.access$10(this.this$0) != null)
          XmppChatActivity.access$10(this.this$0).removeRosterListener(XmppChatActivity.access$11(this.this$0));
        if (XmppChatActivity.access$13(this.this$0) != null)
          XmppChatActivity.access$13(this.this$0).removeChatCreationListener(XmppChatActivity.access$14(this.this$0));
        return;
      }
      catch (RemoteException localRemoteException)
      {
        Loger.e("Chat", localRemoteException.getMessage());
      }
    }
  }
}